package mobi.hami.huapin.dao;

import java.util.Map;

public class SpuSubjectMappingProvider {
    /**
     * 多条件搜索-某个-主题下的商品
     * @param parms
     * @return
     */
    public String subject_products(Map<String,Object> parms){
        StringBuilder sb = new StringBuilder();
        sb.append("select p.id,p.name,p.product_code,p.vodurl,p.first_sortid,p.second_sortid,p.third_sortid from product p where ");
        if(null != parms.get("name") && !parms.get("name").equals("")){
            sb.append("p.name like '%").append(String.valueOf(parms.get("name"))).append("%'").append(" and ");
        }
        if(null != parms.get("product_code") && !parms.get("product_code").equals("")){
            sb.append("p.product_code like '%").append(String.valueOf(parms.get("product_code"))).append("%'").append(" and ");
        }
        if(null != parms.get("subject_id") && !parms.get("subject_id").equals("")){
            sb.append("p.id in (" +
                    "select spu_id from spu_subject_mapping m where m.subject_id = "+parms.get("subject_id")).append(" and ");
            if(null != parms.get("deleted")){
                sb.append("m.deleted =").append(parms.get("deleted"));
            }
            sb.append(")").append(" and ");
        }
        sb.append("1 = 1 ");
        sb.append("order by order_num,gmt_create,gmt_modified desc");
        return sb.toString();
    }

}
